package com.iotteam.androidbase.moudules.sensor_detail.presenter;

import android.text.TextUtils;

import com.iotteam.androidbase.R;
import com.iotteam.androidbase.base.BaseModel;
import com.iotteam.androidbase.commen.LocalInfoManager;
import com.iotteam.androidbase.commen.network.Api;
import com.iotteam.androidbase.commen.network.core.HttpListener;
import com.iotteam.androidbase.commen.network.core.HttpManager;
import com.iotteam.androidbase.commen.utils.ToastUtil;
import com.iotteam.androidbase.moudules.sensor_detail.model.SensorInfoModel;
import com.iotteam.androidbase.moudules.sensor_detail.view.ISensorInfoView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lidechen on 6/4/17.
 */

public class SensorInfoPresenter implements ISensorInfoPresenter {

    private ISensorInfoView mView;

    public SensorInfoPresenter(ISensorInfoView view){
        mView = view;
    }

    @Override
    public void getSensorInfo() {

        //HttpManager.getInstance().postBean(Api.getTerInfo, );
        Map<String, String> param = new HashMap<>();
        param.put("mobile", LocalInfoManager.getInstance().getUserInfo().getMobile());
        HttpManager.getInstance().postBean(Api.getTerInfo, param, SensorInfoModel.class, new HttpListener<SensorInfoModel>() {
            @Override
            public void onSucceed(int what, SensorInfoModel bean) {
                if(bean.getCode() == 0){

                    mView.displaySensorInfo(bean.getData().toString());

                }else{
                    if(!TextUtils.isEmpty(bean.getMessage())) {
                        ToastUtil.showLong(bean.getMessage());
                    }else{
                        ToastUtil.showLong(R.string.dialog_reuest_info_err);
                    }
                }
            }

            @Override
            public void onFailed(int what, Exception e) {
                ToastUtil.showLong(R.string.dialog_reuest_info_err);
            }

            @Override
            public void onStart(int what) {
                mView.showLoading();
            }

            @Override
            public void onFinish(int what) {
                mView.dismissLoading();
            }
        });
    }
}
